package com.molichuxing.services.business.convertor;

import com.molichuxing.framework.property.OperatorTypeEnum;
import com.molichuxing.framework.utils.BigDecimalUtils;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.services.business.dto.request.create.*;
import com.molichuxing.services.business.dto.request.modify.*;
import com.molichuxing.services.business.dto.response.*;
import com.molichuxing.services.infrastructure.dto.request.create.*;
import com.molichuxing.services.infrastructure.dto.request.modify.*;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.property.*;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Convert {

    public static List<UserOrderBizDto> toUserOrderBizDtoBySubscribe(List<OrderSubscribeDto> beanDtoList) {
        List<UserOrderBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderSubscribeDto dto : beanDtoList) {
                beanBizDtoList.add(torUserOrderBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static UserOrderBizDto torUserOrderBizDto(OrderSubscribeDto beanDto) {
        UserOrderBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new UserOrderBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            // 订单类型
            beanBizDto.setOrderType(OrderTypeEnum.SUBSCRIBE);
            // 订单状态
            beanBizDto.setOrderStatus(beanDto.getOrderStatus());
            // 订单金额(租车费+保证金)
            beanBizDto.setOrderAmount(beanDto.getCartFee().add(beanDto.getDeposit()));
        }

        return beanBizDto;
    }

    public static List<UserOrderBizDto> toUserOrderBizDtoByExclusivel(List<OrderExclusivelDto> beanDtoList) {
        List<UserOrderBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderExclusivelDto dto : beanDtoList) {
                beanBizDtoList.add(toUserOrderBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static UserOrderBizDto toUserOrderBizDto(OrderExclusivelDto beanDto) {
        UserOrderBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new UserOrderBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            // 订单类型
            beanBizDto.setOrderType(OrderTypeEnum.EXCLUSIVEL);
            // 订单状态
            beanBizDto.setOrderStatus(beanDto.getOrderStatus());
            // 订单金额(租车费+保证金)
            beanBizDto.setOrderAmount(beanDto.getCartFee().add(beanDto.getDeposit()));
        }

        return beanBizDto;
    }

    public static List<CarOrderBizDto> toCarOrderBizDtoBySubscribe(List<OrderSubscribeDto> beanDtoList) {
        List<CarOrderBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderSubscribeDto dto : beanDtoList) {
                beanBizDtoList.add(toCarOrderBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static CarOrderBizDto toCarOrderBizDto(OrderSubscribeDto beanDto) {
        CarOrderBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new CarOrderBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            // 订单类型
            beanBizDto.setOrderType(OrderTypeEnum.SUBSCRIBE);
            // 订单状态
            beanBizDto.setOrderStatus(beanDto.getOrderStatus());
            // 商品名称(用车时长-付款方式-租车费)
            beanBizDto.setGoodsName(beanDto.getTransportTime() + "个月-" + beanDto.getPaymentMethod().getName() + "-"
                    + BigDecimalUtils.toString(beanDto.getCartFee()) + "元");
        }

        return beanBizDto;
    }

    public static List<CarOrderBizDto> toCarOrderBizDtoByExclusivel(List<OrderExclusivelDto> beanDtoList) {
        List<CarOrderBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderExclusivelDto dto : beanDtoList) {
                beanBizDtoList.add(toCarOrderBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static CarOrderBizDto toCarOrderBizDto(OrderExclusivelDto beanDto) {
        CarOrderBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new CarOrderBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            // 订单类型
            beanBizDto.setOrderType(OrderTypeEnum.EXCLUSIVEL);
            // 订单状态
            beanBizDto.setOrderStatus(beanDto.getOrderStatus());
            // 商品名称(用车时长-付款方式-是否回购-租车费)
            beanBizDto.setGoodsName(beanDto.getTransportTime() + "个月-"
                    + (OrderPaymentMethodEnum.INSTALLMENT.equals(beanDto.getPaymentMethod()) ? "月付"
                    : beanDto.getPaymentMethod().getName())
                    + "-"
                    + (beanDto.getIsBuyback() ? "回购" : "不回购") + "-" + BigDecimalUtils.toString(beanDto.getCartFee())
                    + "元");
        }

        return beanBizDto;
    }

    public static List<OrderSubscribeBizDto> toOrderSubscribeBizDto(List<OrderSubscribeDto> beanDtoList) {
        List<OrderSubscribeBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderSubscribeDto dto : beanDtoList) {
                beanBizDtoList.add(toOrderSubscribeBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static OrderSubscribeBizDto toOrderSubscribeBizDto(OrderSubscribeDto beanDto) {
        OrderSubscribeBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderSubscribeBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            beanBizDto.setType(OrderTypeEnum.SUBSCRIBE);
        }

        return beanBizDto;
    }

    public static OrderSubscribeDetailsBizDto toOrderSubscribeDetailsBizDto(OrderSubscribeDto beanDto) {
        OrderSubscribeDetailsBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderSubscribeDetailsBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            beanBizDto.setType(OrderTypeEnum.SUBSCRIBE);
        }

        return beanBizDto;
    }

    public static OrderUsedCarBizDto toOrderUsedCarBizDto(OrderSubscribeBizDto beanDto) {
        OrderUsedCarBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderUsedCarBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            // 加购里程
            beanBizDto.setReletMileage(beanDto.getPurchaseMileage());
            // 总里程(基础里程+订阅里程+赠送里程+加购里程)
            Integer totalMileage = beanDto.getBaseMileage() + beanDto.getPackageMileage() + beanDto.getGiftMileage();
            if (beanDto.getPurchaseMileage() != null) {
                totalMileage += beanDto.getPurchaseMileage();
            }
            beanBizDto.setTotalMileage(totalMileage);
        }

        return beanBizDto;
    }

    public static List<OrderExclusivelBizDto> toOrderExclusivelBizDto(List<OrderExclusivelDto> beanDtoList) {
        List<OrderExclusivelBizDto> beanBizDtoList = null;
        if (beanDtoList != null && beanDtoList.size() > 0) {
            beanBizDtoList = new ArrayList<>();
            for (OrderExclusivelDto dto : beanDtoList) {
                beanBizDtoList.add(toOrderExclusivelBizDto(dto));
            }
        }

        return beanBizDtoList;
    }

    public static OrderExclusivelBizDto toOrderExclusivelBizDto(OrderExclusivelDto beanDto) {
        OrderExclusivelBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderExclusivelBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            beanBizDto.setType(OrderTypeEnum.EXCLUSIVEL);
            beanBizDto.setExclusivelType(beanDto.getType());
        }

        return beanBizDto;
    }

    public static OrderExclusivelDetailsBizDto toOrderExclusivelDetailsBizDto(OrderExclusivelDto beanDto) {
        OrderExclusivelDetailsBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderExclusivelDetailsBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
            beanBizDto.setType(OrderTypeEnum.EXCLUSIVEL);
            beanBizDto.setExclusivelType(beanDto.getType());
        }

        return beanBizDto;
    }

    public static List<OrderDealerDetailCarInfoBizDto> toOrderDealerDetailCarInfoBizDto(List<OrderDealerDetailCarInfoDto> carList) {
        List<OrderDealerDetailCarInfoBizDto> bizList = null;
        if (carList != null && carList.size() > 0) {
            bizList = new ArrayList<>();
            for (OrderDealerDetailCarInfoDto dto : carList) {
                bizList.add(toOrderDealerDetailCarInfoBizDto(dto));
            }
        }

        return bizList;
    }

    private static OrderDealerDetailCarInfoBizDto toOrderDealerDetailCarInfoBizDto(OrderDealerDetailCarInfoDto beanDto) {
        OrderDealerDetailCarInfoBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderDealerDetailCarInfoBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }

        return beanBizDto;
    }

    public static List<OrderDealerDetailStartBizDto> toOrderDealerDetailStartBizDto(List<OrderDealerDetailStartDto> startList) {
        List<OrderDealerDetailStartBizDto> bizList = null;
        if (startList != null && startList.size() > 0) {
            bizList = new ArrayList<>();
            for (OrderDealerDetailStartDto dto : startList) {
                if (OrderDealerSendCarStatusEnum.NO_SEND.getName().equals(dto.getSendStatus())) {
                    continue;
                }
                bizList.add(toOrderDealerDetailStartBizDto(dto));
            }
        }

        return bizList;
    }

    private static OrderDealerDetailStartBizDto toOrderDealerDetailStartBizDto(OrderDealerDetailStartDto dto) {
        OrderDealerDetailStartBizDto beanBizDto = null;
        if (dto != null) {
            beanBizDto = new OrderDealerDetailStartBizDto();
            BeanUtils.copyProperties(dto, beanBizDto);
        }

        return beanBizDto;
    }

    public static OrderBizDto toOrderBizDto(OrderDto beanDto) {
        OrderBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }

        return beanBizDto;
    }

    public static OrderScheduleOfflineBizDto toOrderScheduleOfflineBizDto(OrderScheduleDto beanDto) {
        OrderScheduleOfflineBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderScheduleOfflineBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }

        return beanBizDto;
    }

    public static List<OrderDealerStatusBizDto> toOrderDealerStatusBizDto(List<OrderDealerDetailStatusDto> dtoList) {
        List<OrderDealerStatusBizDto> bizList = null;
        if (dtoList != null && dtoList.size() > 0) {
            bizList = new ArrayList<>();
            for (OrderDealerDetailStatusDto dto : dtoList) {
                bizList.add(toOrderDealerStatusBizDto(dto));
            }
        }

        return bizList;
    }

    private static OrderDealerStatusBizDto toOrderDealerStatusBizDto(OrderDealerDetailStatusDto beanDto) {
        OrderDealerStatusBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderDealerStatusBizDto();
            beanBizDto.setOrderStatus(beanDto.getOrderStatus().getName());
            beanBizDto.setGmtCreate(beanDto.getGmtCreate());
        }
        return beanBizDto;
    }

    public static OrderMileageBizDto toOrderMileageBizDto(OrderMileageDto beanDto) {
        OrderMileageBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderMileageBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }
        return beanBizDto;
    }

    public static OrderDeliveryBizDto toOrderDeliveryBizDto(OrderDeliveryDto beanDto) {
        OrderDeliveryBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderDeliveryBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }
        return beanBizDto;
    }

    public static OrderReturnBizDto toOrderReturnBizDto(OrderReturnDto beanDto) {
        OrderReturnBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderReturnBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }
        return beanBizDto;
    }

    public static OrderSubscribeSettlementBizDto toOrderSubscribeSettlementBizDto(OrderSubscribeSettlementDto beanDto) {
        OrderSubscribeSettlementBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderSubscribeSettlementBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }
        return beanBizDto;
    }

    public static OrderExclusivelCreateDto toOrderExclusivelCreateDto(Long orderCode,
                                                                      OrderExclusivelCreateBizDto createBizDto) {
        OrderExclusivelCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderExclusivelCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(Long orderCode,
                                                                      OrderExclusivelCreateBizDto createBizDto) {
        OrderStatusFlowCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
            createDto.setOrderStatus(OrderExclusivelStatusEnum.TRADE_UNPAID.getValue());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
            createDto.setOrderUserId(createBizDto.getOperateId());
            createDto.setOrderUserName(createBizDto.getOperateName());
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderTradeDeliveryModifyBizDto modifyBizDto,
                                                                      Integer status) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto == null) {
            return createDto;
        }
        createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(status);
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
        createDto.setOrderUserId(modifyBizDto.getOperateId());
        createDto.setOrderUserName(modifyBizDto.getOperateName());
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderModifyBizDto modifyBizDto,
                                                                      OrderTypeEnum orderType) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(modifyBizDto, createDto);
            createDto.setOrderCode(modifyBizDto.getOrderCode());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(modifyBizDto.getModifiedType().getValue());
            createDto.setOrderUserId(modifyBizDto.getOperateId());
            createDto.setOrderUserName(modifyBizDto.getOperateName());
            if (OrderTypeEnum.SUBSCRIBE.equals(orderType)) {
                OrderSubscribeStatusEnum orderstatus = (OrderSubscribeStatusEnum) modifyBizDto.getOrderStatus();
                createDto.setOrderStatus(orderstatus.getValue());
            } else if (OrderTypeEnum.EXCLUSIVEL.equals(orderType)) {
                OrderExclusivelStatusEnum orderstatus = (OrderExclusivelStatusEnum) modifyBizDto.getOrderStatus();
                createDto.setOrderStatus(orderstatus.getValue());
            }
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderTradeRefundModifyBizDto modifyBizDto,
                                                                      Integer status) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto == null) {
            return createDto;
        }
        createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(status);
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(modifyBizDto.getModifiedType().getValue());
        createDto.setOrderUserId(modifyBizDto.getOperateId());
        createDto.setOrderUserId(modifyBizDto.getOperateId());
        createDto.setOrderUserName(modifyBizDto.getOperateName());
        return createDto;
    }

    public static OrderSubscribeCreateDto toOrderSubscribeCreateDto(Long orderCode,
                                                                    OrderSubscribeCreateBizDto createBizDto) {
        OrderSubscribeCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderSubscribeCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(Long orderCode,
                                                                      OrderSubscribeCreateBizDto createBizDto) {
        OrderStatusFlowCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
            createDto.setOrderStatus(OrderSubscribeStatusEnum.TRADE_UNPAID.getValue());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
            createDto.setOrderUserId(createBizDto.getOperateId());
            createDto.setOrderUserId(createBizDto.getOperateId());
            createDto.setOrderUserName(createBizDto.getOperateName());
        }
        return createDto;
    }

    public static OrderMileageCreateDto toOrderMileageCreateDto(Long orderCode,
                                                                OrderPurchaseCreateBizDto createBizDto) {
        OrderMileageCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderMileageCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
        }
        return createDto;
    }

    public static OrderSubscribeCreateDto toOrderSubscribeCreateDto(Long orderCode,
                                                                    OrderRenewCreateBizDto createBizDto) {
        OrderSubscribeCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderSubscribeCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(Long orderCode,
                                                                      OrderRenewCreateBizDto createBizDto) {
        OrderStatusFlowCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setOrderCode(orderCode);
            createDto.setOrderStatus(OrderSubscribeStatusEnum.TRADE_UNPAID.getValue());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
            createDto.setOrderUserId(createBizDto.getOperateId());
            createDto.setOrderUserId(createBizDto.getOperateId());
            createDto.setOrderUserName(createBizDto.getOperateName());
        }
        return createDto;
    }

    public static OrderScheduleUserCreateDto toOrderScheduleUserCreateDto(OrderPayModifyBizDto modifyDto,
                                                                          OrderExclusivelDto beanDto) {
        OrderScheduleUserCreateDto createDto = new OrderScheduleUserCreateDto();
        createDto.setOrderCode(beanDto.getOrderCode());
        createDto.setUserId(beanDto.getUserId());
        createDto.setPayWay(modifyDto.getPayWay());
        createDto.setPaySuccessTime(modifyDto.getPayTime());
        // 总期数=用车时长/还款周期
        createDto.setTotalPeriods(beanDto.getTransportTime() / beanDto.getRepaymentPeriod());
        createDto.setRepaymentPeriod(beanDto.getRepaymentPeriod());
        createDto.setCartFee(beanDto.getCartFee());
        createDto.setRental(beanDto.getRental());
        createDto.setDeposit(beanDto.getDeposit());
        createDto.setPaymentMethod(beanDto.getPaymentMethod());

        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderPayModifyBizDto modifyBizDto,
                                                                      OrderExclusivelStatusEnum status) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(modifyBizDto, createDto);
            createDto.setOrderCode(modifyBizDto.getOrderCode());
            createDto.setOrderStatus(status.getValue());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
            createDto.setOrderUserId(modifyBizDto.getOperateId());
            createDto.setOrderUserName(modifyBizDto.getOperateName());
        }
        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderPayModifyBizDto modifyBizDto,
                                                                      OrderSubscribeStatusEnum status) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto != null) {
            createDto = new OrderStatusFlowCreateDto();
            BeanUtils.copyProperties(modifyBizDto, createDto);
            createDto.setOrderCode(modifyBizDto.getOrderCode());
            createDto.setOrderStatus(status.getValue());
            createDto.setOrderModifiedTime(LocalDateTime.now());
            createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
            createDto.setOrderUserId(modifyBizDto.getOperateId());
            createDto.setOrderUserName(modifyBizDto.getOperateName());
        }
        return createDto;
    }

    @SuppressWarnings("rawtypes")
    public static OrderPayModifyDto toOrderPayModifyDto(OrderPayModifyBizDto modifyBizDto,
                                                        Enum orderStatus, Integer transportTime, LocalDateTime deliveryDeadline) {
        OrderPayModifyDto modifyDto = null;
        if (modifyBizDto != null) {
            modifyDto = new OrderPayModifyDto();
            BeanUtils.copyProperties(modifyBizDto, modifyDto);
            modifyDto.setOrderStatus(orderStatus);
            modifyDto.setDeliveryDeadline(deliveryDeadline);
            // 起租日
            modifyDto.setLeaseInception(modifyDto.getPayTime().toLocalDate());
            // 截止日（起租日加租期）
            modifyDto.setLeaseExpire(DateUtil
                    .plus(modifyDto.getPayTime(), transportTime, ChronoUnit.MONTHS).toLocalDate());
        }
        return modifyDto;
    }

    public static OrderDeliveryCreateDto toOrderDeliveryCreateDto(OrderTradeDeliveryModifyBizDto modifyBizDto) {
        OrderDeliveryCreateDto createDto = null;
        if (modifyBizDto != null) {
            createDto = new OrderDeliveryCreateDto();
            BeanUtils.copyProperties(modifyBizDto, createDto);
            createDto.setDeliveryTime(LocalDateTime.now());
        }
        return createDto;
    }

    public static OrderAuditCreateDto toOrderAuditCreateDto(OrderTradeAuditModifyBizDto modifyBizDto,
                                                            OrderAuditTypeEnum type) {
        OrderAuditCreateDto createDto = null;
        if (modifyBizDto != null) {
            createDto = new OrderAuditCreateDto();
            BeanUtils.copyProperties(modifyBizDto, createDto);
            createDto.setType(type);
        }
        return createDto;
    }

    public static OrderDeliveryModifyDto toOrderDeliveryModifyDto(OrderTradeDeliveryModifyBizDto modifyBizDto) {
        OrderDeliveryModifyDto modifyDto = null;
        if (modifyBizDto == null) {
            return modifyDto;
        }
        modifyDto = new OrderDeliveryModifyDto();
        BeanUtils.copyProperties(modifyBizDto, modifyDto);

        return modifyDto;
    }

    public static OrderPayModifyDto toOrderPayModifyDto(OrderPayModifyBizDto modifyBizDto) {
        OrderPayModifyDto modifyDto = null;
        if (modifyBizDto == null) {
            return modifyDto;
        }
        modifyDto = new OrderPayModifyDto();
        BeanUtils.copyProperties(modifyBizDto, modifyDto);

        return modifyDto;
    }

    public static OrderFinishModifyDto toOrderFinishModifyDto(OrderExpireModifyBizDto modifyBizDto) {
        OrderFinishModifyDto modifyDto = null;
        if (modifyBizDto == null) {
            return modifyDto;
        }
        modifyDto = new OrderFinishModifyDto();
        modifyDto.setOrderCode(modifyBizDto.getOrderCode());
        modifyDto.setOrderStatus(OrderSubscribeStatusEnum.RETURN_FINISH);
        modifyDto.setEndMileage(modifyBizDto.getCurrentMileage());
        modifyDto.setSettleMileage(modifyBizDto.getCurrentMileage());

        return modifyDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderExpireModifyBizDto modifyBizDto,
                                                                      OrderSubscribeStatusEnum orderStatus) {
        OrderStatusFlowCreateDto createDto = null;
        if (modifyBizDto == null) {
            return createDto;
        }
        createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(orderStatus.getValue());
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.SYSTEM.getValue());
        createDto.setOrderUserId(0);
        createDto.setOrderUserName("system");
        return createDto;
    }

    public static OrderUseModifyDto toOrderUseModifyDto(OrderExpireModifyBizDto modifyBizDto, OrderSubscribeDto renew,
                                                        Integer warningMileage) {
        OrderUseModifyDto modifyDto = null;
        if (modifyBizDto == null) {
            return modifyDto;
        }
        modifyDto = new OrderUseModifyDto();
        modifyDto.setOrderCode(renew.getOrderCode());
        modifyDto.setStartMileage(modifyBizDto.getCurrentMileage());
        modifyDto.setWarningMileage(warningMileage);

        return modifyDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderSubscribeDto renew,
                                                                      OrderSubscribeStatusEnum orderStatus) {
        OrderStatusFlowCreateDto createDto = null;
        if (renew == null) {
            return createDto;
        }
        createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(renew.getOrderCode());
        createDto.setOrderStatus(orderStatus.getValue());
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.SYSTEM.getValue());
        createDto.setOrderUserId(0);
        createDto.setOrderUserName("system");
        return createDto;
    }

    public static OrderScheduleReminderBizDto toOrderScheduleReminderBizDto(OrderExclusivelDto orderExclusivelDto,
                                                                            OrderScheduleDto orderScheduleDto) {
        OrderScheduleReminderBizDto beanBizDto = null;
        if (orderExclusivelDto == null || orderScheduleDto == null) {
            return beanBizDto;
        }
        beanBizDto = new OrderScheduleReminderBizDto();
        BeanUtils.copyProperties(orderScheduleDto, beanBizDto);
        beanBizDto.setScheduleId(orderScheduleDto.getId());
        beanBizDto.setOrderTime(orderExclusivelDto.getOrderTime());
        beanBizDto.setOrderStatus(orderExclusivelDto.getOrderStatus());
        beanBizDto.setStoreId(orderExclusivelDto.getPlaceStoreId());
        beanBizDto.setCarId(orderExclusivelDto.getCarId());
        // 商品名称（用车时长-付款方式-是否回购-租车费）
        beanBizDto.setGoodsName(orderExclusivelDto.getTransportTime() + "个月-月付-"
                + (orderExclusivelDto.getIsBuyback() ? "回购-" : "不回购-") + "租车费" + orderExclusivelDto.getRental());

        return beanBizDto;
    }

    public static OrderSubscribeSettlementCreateDto toOrderSubscribeSettlementCreateDto(
            Long orderCode, BigDecimal damageFee) {
        OrderSubscribeSettlementCreateDto createDto = null;
        if (orderCode == null) {
            return createDto;
        }
        createDto = new OrderSubscribeSettlementCreateDto();
        createDto.setOrderCode(orderCode);
        createDto.setDamageFee(damageFee);
        createDto.setTotalFee(damageFee);
        createDto.setStatus(createDto.getTotalFee().compareTo(BigDecimal.ZERO) > 0
                ? OrderSubscribeSettlementPayStatusEnum.WAIT : OrderSubscribeSettlementPayStatusEnum.FREE_SETTLE);

        return createDto;
    }

    public static OrderSubscribeSettlementModifyDto toOrderSubscribeSettlementModifyDto(
            OrderSubscribeSettlementDto beanDto, BigDecimal damageFee) {
        OrderSubscribeSettlementModifyDto modifyDto = new OrderSubscribeSettlementModifyDto();
        BeanUtils.copyProperties(beanDto, modifyDto);
        modifyDto.setDamageFee(damageFee);
        modifyDto.setTotalFee(beanDto.getBeyondMileageFee().add(beanDto.getBeyondDayFee()).add(damageFee));
        modifyDto.setStatus(modifyDto.getTotalFee().compareTo(BigDecimal.ZERO) > 0 ? null
                : OrderSubscribeSettlementPayStatusEnum.FREE_SETTLE);

        return modifyDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(OrderReturnCarModifyBizDto modifyBizDto) {
        OrderStatusFlowCreateDto createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(OrderSubscribeStatusEnum.RETURN_UNINSPECTED.getValue());
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.C_USER.getValue());
        createDto.setOrderUserId(modifyBizDto.getOperateId());
        createDto.setOrderUserName(modifyBizDto.getOperateName());
        return createDto;
    }

    public static OrderReturnCreateDto toOrderReturnCreateDto(OrderReturnCarModifyBizDto modifyBizDto,
                                                              OrderSubscribeDto beanDto) {
        OrderReturnCreateDto createDto = new OrderReturnCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setCarId(beanDto.getCarId());
        createDto.setReturnTime(LocalDateTime.now());

        return createDto;
    }

    public static OrderReturnCreateDto toOrderReturnCreateDto(OrderReturnCarModifyBizDto modifyBizDto,
                                                              OrderExclusivelDto beanDto) {
        OrderReturnCreateDto createDto = new OrderReturnCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setCarId(beanDto.getCarId());
        createDto.setReturnTime(LocalDateTime.now());
        createDto.setType(OrderReturnTypeEnum.INITIATIVE.getValue());
        createDto.setRecycleState(RecycleStateEnum.FINISH.getValue());
        return createDto;
    }

    public static OrderReturnCreateDto toOrderReturnCreateDto(RecycleCarsCreateBizDto modifyBizDto,
                                                              OrderExclusivelDto beanDto) {
        OrderReturnCreateDto createDto = new OrderReturnCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setCarId(beanDto.getCarId());
        createDto.setReturnTime(modifyBizDto.getRecycleTime());
        createDto.setType(OrderReturnTypeEnum.RISK.getValue());
        createDto.setRecycleState(modifyBizDto.getRecycleState().getValue());
        return createDto;
    }

    public static OrderSubscribeSettlementCreateDto toOrderSubscribeSettlementCreateDto(OrderReturnCarModifyBizDto modifyBizDto,
                                                                                        Integer beyondMileage, Integer beyondDay) {
        OrderSubscribeSettlementCreateDto createDto = new OrderSubscribeSettlementCreateDto();
        // 订单号
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        // 超出里程数
        createDto.setBeyondMileage(beyondMileage);
        // 里程单价
        createDto.setBeyondMileageUnitPrice(modifyBizDto.getBeyondMileageUnitPrice());
        // 结算超里程费用
        createDto.setBeyondMileageFee(beyondMileage == null ? BigDecimal.ZERO
                : createDto.getBeyondMileageUnitPrice().multiply(new BigDecimal(beyondMileage)));
        // 超期天数
        createDto.setBeyondDay(beyondDay);
        // 天数单价
        createDto.setBeyondDayUnitPrice(modifyBizDto.getBeyondDayUnitPrice());
        // 结算超期费用
        createDto.setBeyondDayFee(beyondDay == null ? BigDecimal.ZERO
                : modifyBizDto.getBeyondDayUnitPrice().multiply(new BigDecimal(beyondDay)));
        // 结算总费用
        createDto.setTotalFee(createDto.getBeyondMileageFee().add(createDto.getBeyondDayFee()));
        // 状态
        createDto.setStatus(OrderSubscribeSettlementPayStatusEnum.WAIT);

        return createDto;
    }

    public static OrderRenegeCreateDto toOrderRenegeCreateDto(OrderExclusivelDto beanDto) {
        OrderRenegeCreateDto createDto = null;
        if (beanDto != null) {
            createDto = new OrderRenegeCreateDto();
            createDto.setOrderCode(beanDto.getOrderCode());
            createDto.setUserId(beanDto.getUserId());
            createDto.setBeforeOrderStatus(beanDto.getOrderStatus());
            createDto.setRenegeTime(LocalDateTime.now());
            createDto.setRenegeStatus(OrderRenegeStatusEnum.RENEGE);
            if (OrderExclusivelStatusEnum.TRADE_UNDELIVERY.equals(beanDto.getOrderStatus())) {
                // 待提车退租，需要自动默认费用信息（我司应付）
                createDto.setCostType(OrderRenegeCostTypeEnum.DISBURSE);
                // 费用为用户支付的所有费用（租金+保证金）
                createDto.setCostAmount(beanDto.getRental().add(beanDto.getDeposit()));
                createDto.setCostTime(LocalDateTime.now());
            }
        }
        return createDto;
    }

    public static OrderRenegeBizDto toOrderRenegeBizDto(OrderRenegeDto beanDto) {
        OrderRenegeBizDto beanBizDto = null;
        if (beanDto != null) {
            beanBizDto = new OrderRenegeBizDto();
            BeanUtils.copyProperties(beanDto, beanBizDto);
        }
        return beanBizDto;
    }

    public static OrderRenegePayeeModifyDto toOrderRenegePayeeModifyDto(OrderRenegePayeeModifyBizDto modifyBizDto) {
        OrderRenegePayeeModifyDto modifyDto = null;
        if (modifyBizDto != null) {
            modifyDto = new OrderRenegePayeeModifyDto();
            BeanUtils.copyProperties(modifyBizDto, modifyDto);
            modifyDto.setPayeeTime(LocalDateTime.now());
        }
        return modifyDto;
    }

    public static OrderEnterpriseCreateDto toOrderEnterpriseCreateDto(OrderEnterpriseCreateBizDto createBizDto) {
        if (createBizDto == null) {
            return null;
        }
        OrderEnterpriseCreateDto createDto = new OrderEnterpriseCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        return createDto;
    }

    public static EnterpriseCarCreateDto toEnterpriseCarCreateDto(OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto createBizDto) {
        if (createBizDto == null) {
            return null;
        }
        EnterpriseCarCreateDto createDto = new EnterpriseCarCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        return createDto;
    }

    public static EnterpriseStateFlowCreateDto toEnterpriseStateFlowCreateDto(Long orderCode, OrderEnterpriseCreateBizDto createBizDto) {
        if (createBizDto == null) {
            return null;
        }
        EnterpriseStateFlowCreateDto createDto = new EnterpriseStateFlowCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        createDto.setOrderCode(orderCode);
        createDto.setOrderStatus(EnterpriseStateEnum.UNPAID.getValue());
        createDto.setOperatorId(createBizDto.getOperateId());
        createDto.setOperatorName(createBizDto.getOperateName());
        createDto.setModifiedType((OperatorTypeEnum.OP.equals(createBizDto.getOperatorType()) || OperatorTypeEnum.DEALER.equals(createBizDto.getOperatorType())) ?
                OrderStatusFlowModifiedTypeEnum.B_USER.getValue() :
                OperatorTypeEnum.MEMBER.equals(createBizDto.getOperatorType()) ?
                        OrderStatusFlowModifiedTypeEnum.C_USER.getValue() : OrderStatusFlowModifiedTypeEnum.B_USER.getValue());
        createDto.setModifiedTime(LocalDateTime.now());

        return createDto;
    }

    public static EnterpriseStateFlowCreateDto toEnterpriseStateFlowCreateDto(EnterprisePayModifyBizDto modifyBizDto,
                                                                              EnterpriseStateEnum newState) {
        if (modifyBizDto == null) {
            return null;
        }
        EnterpriseStateFlowCreateDto createDto = new EnterpriseStateFlowCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(newState.getValue());
        createDto.setOperatorId(modifyBizDto.getOperateId());
        createDto.setOperatorName(modifyBizDto.getOperateName());
        createDto.setModifiedType((OperatorTypeEnum.OP.equals(modifyBizDto.getOperatorType())
                || OperatorTypeEnum.DEALER.equals(modifyBizDto.getOperatorType())) ?
                OrderStatusFlowModifiedTypeEnum.B_USER.getValue() :
                OperatorTypeEnum.MEMBER.equals(modifyBizDto.getOperatorType()) ?
                        OrderStatusFlowModifiedTypeEnum.C_USER.getValue() : OrderStatusFlowModifiedTypeEnum.B_USER.getValue());

        createDto.setModifiedTime(LocalDateTime.now());

        return createDto;
    }


    public static EnterpriseStateFlowCreateDto toEnterpriseStateFlowCreateDto(OrderEnterpriseLeaseConfirmBizDto modifyBizDto,
                                                                              EnterpriseStateEnum newState) {
        if (modifyBizDto == null) {
            return null;
        }
        EnterpriseStateFlowCreateDto createDto = new EnterpriseStateFlowCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(newState.getValue());
        createDto.setOperatorId(modifyBizDto.getOperateId());
        createDto.setOperatorName(modifyBizDto.getOperateName());
        createDto.setModifiedType((OperatorTypeEnum.OP.equals(modifyBizDto.getOperatorType())
                || OperatorTypeEnum.DEALER.equals(modifyBizDto.getOperatorType())) ?
                OrderStatusFlowModifiedTypeEnum.B_USER.getValue() :
                OperatorTypeEnum.MEMBER.equals(modifyBizDto.getOperatorType()) ?
                        OrderStatusFlowModifiedTypeEnum.C_USER.getValue() : OrderStatusFlowModifiedTypeEnum.B_USER.getValue());

        createDto.setModifiedTime(LocalDateTime.now());

        return createDto;

    }


    public static EnterpriseStateFlowCreateDto toEnterpriseStateFlowCreateDto(Long orderCode, OrderEnterpriseDeliveryCreateBizDto createBizDto) {
        if (createBizDto == null) {
            return null;
        }
        EnterpriseStateFlowCreateDto createDto = new EnterpriseStateFlowCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        createDto.setOrderCode(orderCode);
        createDto.setOrderStatus(EnterpriseStateEnum.UNHIRE.getValue());
        createDto.setOperatorId(createBizDto.getOperateId());
        createDto.setOperatorName(createBizDto.getOperateName());
        createDto.setModifiedType((OperatorTypeEnum.OP.equals(createBizDto.getOperatorType()) || OperatorTypeEnum.DEALER.equals(createBizDto.getOperatorType())) ?
                OrderStatusFlowModifiedTypeEnum.B_USER.getValue() :
                OperatorTypeEnum.MEMBER.equals(createBizDto.getOperatorType()) ?
                        OrderStatusFlowModifiedTypeEnum.C_USER.getValue() : OrderStatusFlowModifiedTypeEnum.B_USER.getValue());
        createDto.setModifiedTime(LocalDateTime.now());

        return createDto;
    }

    public static EnterpriseStateFlowCreateDto toEnterpriseStateFlowCreateDto(EnterpriseRenewLeaseModifyBizDto modifyBizDto) {

        if (modifyBizDto == null) {
            return null;
        }

        EnterpriseStateFlowCreateDto createDto = new EnterpriseStateFlowCreateDto();
        createDto.setOrderCode(modifyBizDto.getOrderCode());
        createDto.setOrderStatus(EnterpriseStateEnum.DELIVERY.getValue());
        createDto.setOperatorId(0);
        createDto.setOperatorName("system");
        createDto.setModifiedType(OrderStatusFlowModifiedTypeEnum.SYSTEM.getValue());
        createDto.setModifiedTime(LocalDateTime.now());
        createDto.setRemark("续订起租");

        return createDto;
    }

    public static EnterpriseScheduleCreateBizDto toEnterpriseScheduleCreateBizDto(OrderEnterpriseDto order,
                                                                                  EnterprisePayModifyBizDto modifyBizDto) {
        if (order == null || modifyBizDto == null) {
            return null;
        }
        EnterpriseScheduleCreateBizDto createBizDto = new EnterpriseScheduleCreateBizDto();
        BeanUtils.copyProperties(modifyBizDto, createBizDto);
        createBizDto.setEnterpriseId(order.getEnterpriseId());
        createBizDto.setPeriods(1);
        // 总期数 = 租期 / 还款周期
        createBizDto.setTotalPeriods((int) Math.ceil(order.getTenancy() / order.getRepaymentPeriod()));
        createBizDto.setPayableDate(modifyBizDto.getPayTime().toLocalDate());
        // 实付金额(不包含保证金)
        createBizDto.setArrivalAmount(modifyBizDto.getArrivalAmount().subtract(order.getDeposit()));

        return createBizDto;
    }

    public static List<EnterpriseScheduleBizDto> toEnterpriseScheduleBizDtoList(List<EnterpriseScheduleDto> dtoList,
                                                                                Map<Long, OrderEnterpriseDto> enterpriseMap, Map<Integer, EnterpriseScheduleCarCountDto> scheduleCarMap) {
        List<EnterpriseScheduleBizDto> bizDtoList = new ArrayList<>();
        if (dtoList != null && dtoList.size() > 0) {
            for (EnterpriseScheduleDto dto : dtoList) {
                bizDtoList.add(toEnterpriseScheduleBizDto(dto, enterpriseMap, scheduleCarMap));
            }
        }
        return bizDtoList;
    }

    public static EnterpriseScheduleBizDto toEnterpriseScheduleBizDto(EnterpriseScheduleDto dto,
                                                                      Map<Long, OrderEnterpriseDto> enterpriseMap, Map<Integer, EnterpriseScheduleCarCountDto> scheduleCarMap) {
        EnterpriseScheduleBizDto beanDto = null;
        if (dto != null) {
            beanDto = new EnterpriseScheduleBizDto();
            BeanUtils.copyProperties(dto, beanDto);
            Long orderCode = dto.getOrderCode();
            Integer scheduleId = dto.getScheduleId();
            LocalDate payableDate = dto.getPayableDate();
            long daysDiff = DateUtil.getDaysDiff(payableDate, LocalDate.now());
            beanDto.setOverdueDays((int) daysDiff);

            if (enterpriseMap != null && enterpriseMap.size() > 0) {
                OrderEnterpriseDto orderEnterpriseDto = enterpriseMap.get(orderCode);
                if (orderEnterpriseDto != null) {
                    Integer tenancy = orderEnterpriseDto.getTenancy();
                    Integer repaymentPeriod = orderEnterpriseDto.getRepaymentPeriod();
                    beanDto.setTenancy(tenancy);
                    beanDto.setRepaymentPeriod(repaymentPeriod);
                }
            }
            if (scheduleCarMap != null && scheduleCarMap.size() > 0) {
                EnterpriseScheduleCarCountDto enterpriseScheduleCarCountDto = scheduleCarMap.get(scheduleId);
                if (enterpriseScheduleCarCountDto != null) {
                    Integer carCount = enterpriseScheduleCarCountDto.getCarCount();
                    if (null == carCount) {
                        carCount = 0;
                    }
                    BigDecimal allPayable = enterpriseScheduleCarCountDto.getAllPayable();
                    if (null == allPayable) {
                        allPayable = new BigDecimal("0");
                    }
                    beanDto.setCarCount(carCount);
                    beanDto.setAllPayable(allPayable);
                } else {
                    beanDto.setCarCount(0);
                    beanDto.setAllPayable(new BigDecimal("0"));
                }
            }
        }
        return beanDto;
    }

    public static EnterpriseScheduleCreateDto toEnterpriseScheduleCreateDto(EnterpriseScheduleCreateBizDto createBizDto) {
        if (createBizDto == null) {
            return null;
        }
        EnterpriseScheduleCreateDto createDto = new EnterpriseScheduleCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        createDto.setState(EnterpriseScheduleStateEnum.ALREADY);

        return createDto;
    }

    public static List<EnterpriseScheduleCarCreateDto> toEnterpriseScheduleCarCreateDto(Integer scheduleId,
                                                                                        List<EnterpriseCarDto> dtos,
                                                                                        EnterpriseScheduleStateEnum state) {

        if (dtos == null || dtos.isEmpty()) {
            return null;
        }
        List<EnterpriseScheduleCarCreateDto> createDtos = new ArrayList<>();
        dtos.forEach(dto -> {
            createDtos.add(toEnterpriseScheduleCarCreateDto(scheduleId, dto, state));

        });

        return createDtos;
    }

    public static EnterpriseScheduleCarCreateDto toEnterpriseScheduleCarCreateDto(Integer scheduleId,
                                                                                  EnterpriseCarDto dto,
                                                                                  EnterpriseScheduleStateEnum state) {
        if (dto == null) {
            return null;
        }
        EnterpriseScheduleCarCreateDto createDto = new EnterpriseScheduleCarCreateDto();
        createDto.setScheduleId(scheduleId);
        createDto.setCarId(dto.getCarId());
        createDto.setPayable(dto.getPeriodsRental());
        createDto.setState(state == null ? EnterpriseScheduleStateEnum.NO : state);

        return createDto;
    }

    public static List<EnterpriseScheduleBizDto> toEnterpriseScheduleBizDto(List<EnterpriseScheduleDto> scheduleDtos,
                                                                            Map<Integer, EnterpriseScheduleCarCountDto> scheduleCarMap) {
        if (scheduleDtos == null || scheduleDtos.isEmpty() ||
                scheduleCarMap == null || scheduleCarMap.isEmpty()) {
            return null;
        }
        List<EnterpriseScheduleBizDto> bizDtos = new ArrayList<>();
        for (EnterpriseScheduleDto scheduleDto : scheduleDtos) {
            EnterpriseScheduleCarCountDto carCountDto = scheduleCarMap.get(scheduleDto.getScheduleId());
            bizDtos.add(toEnterpriseScheduleBizDto(scheduleDto, carCountDto));
        }

        return bizDtos;

    }

    public static EnterpriseScheduleBizDto toEnterpriseScheduleBizDto(EnterpriseScheduleDto dto,
                                                                      EnterpriseScheduleCarCountDto carCountDto) {
        if (dto == null || carCountDto == null) {
            return null;
        }
        EnterpriseScheduleBizDto bizDto = new EnterpriseScheduleBizDto();
        BeanUtils.copyProperties(dto, bizDto);
        // 状态
        bizDto.setStateStr(EnterpriseScheduleStateEnum.getName(bizDto.getState()));
        // 应还金额
        bizDto.setAllPayable(carCountDto.getAllPayable());
        // 计算逾期天数
        LocalDate temp = LocalDate.now();
        if (dto.getState() == EnterpriseScheduleStateEnum.ALREADY.getValue()) {
            // 已还款
            temp = dto.getPayTime().toLocalDate();
        }
        long daysDiff = DateUtil.getDaysDiff(dto.getPayableDate(), temp);
        bizDto.setOverdueDays(daysDiff > 0L ? (int) daysDiff : 0);

        return bizDto;
    }

    public static EnterpriseExpireBizDto toEnterpriseExpireBizDto(OrderEnterpriseDto enterprise,
                                                                  List<EnterpriseCarDto> enterpriseCars) {
        if (enterprise == null) {
            return null;
        }
        EnterpriseExpireBizDto bizDto = new EnterpriseExpireBizDto();
        BeanUtils.copyProperties(enterprise, bizDto);
        bizDto.setCarList(new ArrayList<>());
        for (EnterpriseCarDto enterpriseCar : enterpriseCars) {
            EnterpriseExpireBizDto.EnterpriseCarExpireBizDto carBizDto = bizDto.new EnterpriseCarExpireBizDto();
            BeanUtils.copyProperties(enterpriseCar, carBizDto);
            bizDto.getCarList().add(carBizDto);
        }

        return bizDto;
    }

    public static EnterpriseRenewBizDto toEnterpriseRenewBizDto(OrderEnterpriseDto enterprise,
                                                                List<EnterpriseCarDto> enterpriseCars) {

        if (enterprise == null) {
            return null;
        }
        EnterpriseRenewBizDto bizDto = new EnterpriseRenewBizDto();
        BeanUtils.copyProperties(enterprise, bizDto);
        bizDto.setCarList(new ArrayList<>());
        for (EnterpriseCarDto enterpriseCar : enterpriseCars) {
            EnterpriseRenewCarBizDto carBizDto = new EnterpriseRenewCarBizDto();
            BeanUtils.copyProperties(enterpriseCar, carBizDto);
            bizDto.getCarList().add(carBizDto);
        }

        return bizDto;
    }

    public static EnterpriseCarHandoverCreateDto toEnterpriseCarHandoverCreateDto(OrderEnterpriseReturnCreateBizDto createBizDto,
                                                                                  EnterpriseCarDto enterpriseCar) {
        EnterpriseCarHandoverCreateDto createDto = null;
        if (createBizDto != null) {
            createDto = new EnterpriseCarHandoverCreateDto();
            BeanUtils.copyProperties(createBizDto, createDto);
            createDto.setHandoverTime(LocalDateTime.now());
            if (enterpriseCar != null) {
                createDto.setLicencePlate(enterpriseCar.getLicencePlate());
                createDto.setColorId(enterpriseCar.getColorId());
                createDto.setModelId(enterpriseCar.getModelId());
                createDto.setStartMileage(enterpriseCar.getStartMileage());
            }
        }
        return createDto;
    }

    public static EnterpriseCarModifyDto toEnterpriseCarModifyDto(OrderEnterpriseReturnCreateBizDto createBizDto,
                                                                  EnterpriseCarDto enterpriseCar) {
        EnterpriseCarModifyDto modifyDto = null;
        if (createBizDto != null) {
            modifyDto = new EnterpriseCarModifyDto();
            BeanUtils.copyProperties(createBizDto, modifyDto);
            modifyDto.setEndMileage(createBizDto.getReturnMileage());
        }
        return modifyDto;
    }

    public static EnterpriseCarHandoverCreateDto toEnterpriseCarHandoverCreateDto(OrderEnterpriseDeliveryCreateBizDto bean, EnterpriseCarDto enterpriseCar) {
        EnterpriseCarHandoverCreateDto dto = null;
        if (bean != null) {
            dto = new EnterpriseCarHandoverCreateDto();
            BeanUtils.copyProperties(bean, dto);
            dto.setHandoverTime(LocalDateTime.now());
            if (enterpriseCar != null) {
                dto.setLicencePlate(enterpriseCar.getLicencePlate());
                dto.setColorId(enterpriseCar.getColorId());
                dto.setModelId(enterpriseCar.getModelId());
                dto.setStartMileage(enterpriseCar.getStartMileage());
            }
        }
        return dto;
    }

    public static EnterpriseCarModifyDto toEnterpriseCarModifyDto(OrderEnterpriseDeliveryCreateBizDto bean, EnterpriseCarDto enterpriseCar) {
        EnterpriseCarModifyDto dto = null;
        if (bean != null) {
            dto = new EnterpriseCarModifyDto();
            BeanUtils.copyProperties(bean, dto);
        }
        return dto;
    }

    public static LawsuitCreateDto toLawsuitCreateDto(LawsuitCreateBizDto createBizDto, OrderExclusivelDto orderExclusivel,
                                                      OverdueBizDto overdue) {
        if (createBizDto == null || orderExclusivel == null) {
            return null;
        }
        overdue = overdue == null ? new OverdueBizDto(0, 0) : overdue;
        LawsuitCreateDto createDto = new LawsuitCreateDto();
        BeanUtils.copyProperties(createBizDto, createDto);
        createDto.setUserId(orderExclusivel.getUserId());
        createDto.setOverdueDaysTotal(overdue.getOverdueDays());
        createDto.setOverdueNumTotal(overdue.getOverdueNum());
        createDto.setLawsuitState(LawsuitStateEnum.PROGRESS);
        createDto.setLawsuitTime(LocalDateTime.now());

        return createDto;
    }

    public static OrderStatusFlowCreateDto toOrderStatusFlowCreateDto(LawsuitCreateBizDto createBizDto) {
        OrderStatusFlowCreateDto createDto = new OrderStatusFlowCreateDto();
        createDto.setOrderCode(createBizDto.getOrderCode());
        createDto.setOrderStatus(OrderExclusivelStatusEnum.LAWSUIT.getValue());
        createDto.setOrderModifiedTime(LocalDateTime.now());
        createDto.setOrderModifiedType(OrderStatusFlowModifiedTypeEnum.B_USER.getValue());
        createDto.setOrderUserId(createBizDto.getOperateId());
        createDto.setOrderUserName(createBizDto.getOperateName());
        return createDto;
    }

    public static OrderRecycleCarsModifyDto toOrderRecycleCarsModifyDto(RecycleCarsCreateBizDto modifyBizDto) {
        if (modifyBizDto == null) {
            return null;
        }

        OrderRecycleCarsModifyDto modifyDto = new OrderRecycleCarsModifyDto();
        modifyDto.setOrderCode(modifyBizDto.getOrderCode());
        modifyDto.setRecycleState(modifyBizDto.getRecycleState().getValue());
        modifyDto.setReturnTime(modifyBizDto.getRecycleTime());

        return modifyDto;

    }

    public static RecycleCarsCreateDto toRecycleCarsCreateDto(RecycleCarsCreateBizDto modifyBizDto,
                                                              OrderExclusivelDto dto) {
        if (modifyBizDto == null || dto == null) {
            return null;
        }

        RecycleCarsCreateDto createDto = new RecycleCarsCreateDto();
        BeanUtils.copyProperties(modifyBizDto, createDto);
        createDto.setCarId(dto.getCarId());
        createDto.setUserId(dto.getUserId());

        return createDto;
    }
}
